<?php 
namespace plugin;
class Admin extends \Plugin {
	
	protected $_admin_auth = 1;

	public function index(){

		$pagenum = 50;
		$page = \mylib\Input::get('page', 1);

		$data = \Ebcms::db() -> select('guestbook', '*', [
			'ORDER' => [
				'id' => 'DESC',
			],
			'LIMIT'=>[($page-1) * $pagenum, $pagenum]
		]);
		$this -> assign('data', $data);

		$total = \Ebcms::db() -> count('guestbook');
		$this -> assign('pages', \Ebcms::page($total, $page, $pagenum));

		return \mylib\Response::html($this -> fetch());
	}

	public function remark(){
		if (\Ebcms::isPost()) {
			\Ebcms::db() -> update('guestbook', [
				'remark'=>\mylib\Input::post('remark'),
			], [
				'id'=>\mylib\Input::post('id')
			]);
			return $this -> success('操作成功！', plugin_url('/guestbook/admin/index'));
		}else{
			$data = \Ebcms::db() -> get('guestbook', '*', ['id'=>\mylib\Input::get('id')]);
			$this -> assign('data', $data);
			return \mylib\Response::html($this -> fetch());
		}
	}

	public function del(){
		if (\Ebcms::isAjax()) {
			\Ebcms::db() -> delete('guestbook', [
				'id'=>\mylib\Input::post('id'),
			]);
			return $this -> success('操作成功！');
		}
	}
}